package com.lzj.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzj.demo.dto.Storage;
import com.lzj.demo.mapper.StorageMapper;
import com.lzj.demo.service.StorageService;
import org.springframework.stereotype.Service;

/**
 * (Storage)表服务实现类
 *
 * @author makejava
 * @since 2023-02-09 09:51:44
 */
@Service
public class StorageServiceImpl extends ServiceImpl<StorageMapper, Storage> implements StorageService {

    @Override
    public boolean decrease(Long productId, Integer count) {
        Storage storage = lambdaQuery().eq(Storage::getProductId,productId).one();
        return lambdaUpdate().set(Storage::getUsed,storage.getUsed() + count)
                .set(Storage::getResidue,storage.getResidue() - count)
                .eq(Storage::getProductId,productId).update();
    }
}

